package tech.yunland.shop.domain.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.moyuer.bsf.domain.model.AbstractVersionEntity;
import com.moyuer.bsf.domain.model.Role;
import com.moyuer.bsf.domain.model.User;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 职位提成
 *
 * @author: 袁首京<yuanshoujing@gmail.com>
 * 16/4/22
 */
@Entity
@Table(name = "job_prize")
public class JobPrize extends AbstractVersionEntity {

    @JSONField(serialize = false)
    @ManyToOne(optional = false)
    private Role job; // 职位

    @NotNull
    @Column(name = "prize_type", nullable = false)
    private Integer prizeType; // 计提类型, 10 固定金额 20 百分比

    @NotNull
    @Column(name = "prize_value", nullable = false)
    private BigDecimal prizeValue; // 计提值

    @JSONField(format = "yyyy-MM-dd")
    @Column(name = "start_date", nullable = false)
    private Date startDate = new Date(); // 生效日期

    @Column(nullable = false)
    private Integer state = 0; // -1 标记删除 0 创建 1 生效

    @JSONField(serialize = false)
    @ManyToOne
    private User creator; // 创建人

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "create_time", nullable = false, insertable = false, updatable = false)
    private Date createTime;

    @NotNull
    @Column(name = "organ_id")
    private String organId;//机构
    
    @Transient
    private String jobId;
    @Transient
    private String jobName;

    @Transient
    private String creatorId;
    @Transient
    private String creatorName;
    

    public Role getJob() {
        return job;
    }

    public void setJob(Role job) {
        this.job = job;
    }

    public Integer getPrizeType() {
        return prizeType;
    }

    public void setPrizeType(Integer prizeType) {
        this.prizeType = prizeType;
    }

    public BigDecimal getPrizeValue() {
        return prizeValue;
    }

    public void setPrizeValue(BigDecimal prizeValue) {
        this.prizeValue = prizeValue;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public User getCreator() {
        return creator;
    }

    public void setCreator(User creator) {
        this.creator = creator;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getJobId() {
        if (jobId != null) {
            return jobId;
        }

        if (job != null) {
            jobId = job.getId();
        }

        return jobId;
    }

    public void setJobId(String jobId) {
        this.jobId = jobId;
    }

    public String getJobName() {
        if (jobName != null) {
            return jobName;
        }

        if (job != null) {
            jobName = job.getName();
        }

        return jobName;
    }

    public void setJobName(String jobName) {
        this.jobName = jobName;
    }

    public String getCreatorId() {
        if (creatorId != null) {
            return creatorId;
        }

        if (creator != null) {
            creatorId = creator.getId();
        }

        return creatorId;
    }

    public void setCreatorId(String creatorId) {
        this.creatorId = creatorId;
    }

    public String getCreatorName() {
        if (creatorName != null) {
            return creatorName;
        }

        if (creator != null) {
            creatorName = creator.getName();
        }
        return creatorName;
    }

    public void setCreatorName(String creatorName) {
        this.creatorName = creatorName;
    }

	public String getOrganId() {
		return organId;
	}

	public void setOrganId(String organId) {
		this.organId = organId;
	}
}
